package com.mazaiting.course.utils;

import com.mazaiting.course.exception.CustomException;
import com.mazaiting.course.exception.ExceptionEnum;

import java.util.regex.Pattern;

public class RegexMatchesUtils {

    /**
     * 值允许数字 字母 汉字 进入
     * @param username
     */
    public static void isMatches(String username){
        String CHECKsql = "^(\\d|\\w|[\\u4e00-\\u9fa5)])*$";
        if(!Pattern.matches(CHECKsql, username)){
            throw new CustomException(ExceptionEnum.PARAM_ILLEGA);
        }
    }

    /**
     * 值允许数字 字母 汉字 进入
     * @param secret
     */
    public static void isMatchesSecret(String secret){
        String CHECKsql = "^(\\d|\\w|[-]|[\\u4e00-\\u9fa5)])*$";
        if(!Pattern.matches(CHECKsql, secret)){
            throw new CustomException(ExceptionEnum.PARAM_ILLEGA);
        }
    }
}
